package com.kaishengit.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.kaishengit.entity.Employee;
import com.kaishengit.service.EmployeeService;
import com.kaishengit.service.GoalService;
import com.kaishengit.service.TaskEmployeeService;
import com.kaishengit.service.TaskService;
import com.kaishengit.util.StringUtil;
import com.kaishengit.util.db.Page;

public class NewTask extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String goalid = request.getParameter("goalid");
		com.kaishengit.entity.Goal goal = new GoalService().findById(goalid);
		request.setAttribute("goal", goal);
		request.getRequestDispatcher("WEB-INF/views/newtask.jsp").forward(request, response);
		
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		HttpSession session = request.getSession();
		Employee employee = (Employee)session.getAttribute("employee");
		
		com.kaishengit.entity.Goal goal = (com.kaishengit.entity.Goal)session.getAttribute("goal");
		
		
		String name = request.getParameter("name");
		String desc = request.getParameter("desc");
		String endtime = request.getParameter("endtime");
		String state = request.getParameter("state");
		String level = request.getParameter("level");
		String employeeid = employee.getId();
		String projectid = (String) session.getAttribute("p");
		com.kaishengit.entity.Task task = new com.kaishengit.entity.Task();
		task.setId(StringUtil.getId());
		task.setName(name);
		task.setDesc(desc);
		task.setEndtime(endtime);
		task.setState(state);
		task.setLevel(level);
		task.setEmployeeid(employeeid);
		task.setGoalid(goal.getId());
		new TaskService().add(task);
		
		List<com.kaishengit.entity.TaskEmployee> list = new TaskEmployeeService().findByGoalId(task.getGoalid());
		request.setAttribute("list", list);
		request.getRequestDispatcher("WEB-INF/views/task.jsp").forward(request, response);
		
		
	}

}
